//js文件要放标签后面

const rememberTheme = localStorage.getItem('storage_theme');
if(rememberTheme && ['dark','light'].includes(rememberTheme)){
    document.documentElement.setAttribute('data-color-mode',rememberTheme);
}

const button = document.querySelector('#darkMode');
button.onclick = () =>{
  //const html_doc = document.getElementsByTagName('html')[0];
  //const mode = html_doc.getAttribute('data-color-mode') == 'dark' ? 'light' : 'dark';
  
  const theme = document.documentElement.dataset.colorMode;    //获取data开头的自定义属性值（用-分隔驼峰式获取、驼峰式定义用小写获取）
  const mode  = theme === 'light' ? 'dark' : 'light';
  document.documentElement.setAttribute('data-color-mode',mode);
  localStorage.setItem('storage_theme',mode);
}
